"""
小程序码
"""
import os
import sys
import json
import django

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(os.path.abspath(__file__))
print(BASE_DIR)
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()
import uuid
from core.wchat.mini_base import wechat_client
from core.tools.oss_upload import oss_upload_file
from core.wchat.wx_base import mc


def make_mini_code(page="pages/member/index"):
    level = 1  # 会员等级  1 黄金 2石
    channel_key = "guangda"
    expire = 365
    data = {"level": level, "channel": channel_key, "expire": expire}
    scene = json.dumps(data)    # 32个长度  需要注意  目前超出了
    # print(data, "sss")
    key = uuid.uuid1().hex
    mc.set(key, scene)
    print("32位scene为：", key)
    response = wechat_client.wxa.get_wxa_code_unlimited(key, page=page)
    # print(key)
    url = oss_upload_file(response.content)
    print(channel_key, url)
    return url


if __name__ == '__main__':
    make_mini_code(page="pages/member/index")
